const htpp_img = 'http://video.yellowei.top/' //图片访问地址
const http_img_download = 'https://szycjw.oss-cn-shenzhen-internal.aliyuncs.com ' //图片下载地址
// const host_http = "http://192.168.0.191:1235/";
const host_http = "https://zaixianjiaoyu.szycjw.com/";
const invite_http = "https://zaixian.szycjw.com/index.html";
// const host_http = "http://147.135.164.113:8836/";
// const host_http = "https://ceshi.xiaozhiling.cn/";
// const host_http = "http://vonline_education.szycjw.com/";
const host_http_second = "http://ku.qingnian8.com/school/list.php";
// const host_http = "//47.119.140.191:5556/newDemoProjectToken/generator/";
const host_websocket = "ws://192.168.0.188:3636/hello" // WebSocket接口
// const host_websocket = "ws://47.119.140.191:3636/hello" // WebSocket接口

// let header_url ='response.setHeader("Access-Control-Allow-Origin", "*");'
const api = {
	customSave: 'custom/save', //注册
	sendEmail: 'sendEmail',
	login: 'login',
	chat_information_query: 'chat_information_query',
	latest_query: 'latest_query',
	user_comments_teacher: 'user_comments_teacher',
	mailbox_registration: 'mailbox_registration', //学生邮箱注册
	verification_code: 'verification_code', //发送手机验证码
	phone_register: 'phone_register', //学生手机注册
	phone_password_login: 'phone_password_login', //学生手机登录
	student_phone_existence: 'student_phone_existence', // 学生手机号是否注册
	student_mailbox_existence: 'student_mailbox_existence', // 学生邮箱是否注册
	student_mailbox_password: 'student_mailbox_password', // 学生邮箱修改
	student_phone_update: 'student_phone_update', //学生手机号修改
	looking_teachers: 'looking_teachers', //查找老师
	development_add: 'development_add', // 企业咨询
	teaching_period_query: "teaching_period_query", //查找老师上课时间
	learning_objectives_add: "learning_objectives_add", // 老师了解信息
	Secondary_registration: 'Secondary_registration', //老师注册信息
	details: 'details', //老师详细信息上传
	skill_addition: 'skill_addition', //担任多个科目
	getSign: "getSign", //oss签证上传
	teaching_time: "teaching_time",	//授课时间
	student_mailbox_phone_update: 'student_mailbox_phone_update', //邮箱手机号修改
	student_detailed_query: 'student_detailed_query',
	student_password_update1: 'student_password_update1',
	credit_card: "credit_card",//付款接口
	looking_teachers_money: 'looking_teachers_money',//查找付款信息
	chat_content_add: 'chat_content_add',//学生端发信息
	teacher_img_update: 'teacher_img_update', // 档案老师头像上传
	// looking_teachers: 'looking_teachers', //查询老师档案图片接口
	teacher_not_examine: 'teacher_not_examine',   //查询内容
	teacher_sendEmail: 'teacher_sendEmail', //发送邮箱通知审核老师
	teacher_query_skill: 'teacher_query_skill',//查询担任科目
	teacher_update_skill: 'teacher_update_skill', //修改科目
	teacher_img_update: 'teacher_img_update', // 档案老师头像上传
	chat_content_add: 'chat_content_add',//学生端发信息
	password_change: 'password_change', //变更密码
	cancel_account: 'cancel_account',//注销账号
	teacher_self_introduction_update: 'teacher_self_introduction_update', //老师介绍修改
	teacher_information_update: 'teacher_information_update',  //老师描述修改
	lecture_time: 'lecture_time', //缓存课程预约时间
	student_issue_task: 'student_issue_task',// 学生颁布任务
	student_task_query1: 'student_task_query1', //查询学生任务
	student_task_del: 'student_task_del', //删除任务
	personal_configuration_add: 'personal_configuration_add',  // 文件验证
	student_lecture_time_record: 'student_lecture_time_record',
	query_teacher_background: 'query_teacher_background',//是否填写个人背景
	update_class_time: 'update_class_time',// (老师上课提前通知几小时学生上课)
	teacher_notice_query: 'teacher_notice_query', // 设置通知提醒
	conversiontime: "conversiontime",
	student_query_curriculum_record: 'student_query_curriculum_record',
	order_query: 'order_query',
	ergodic_query: 'ergodic_query',
	information_addition_add: 'information_addition_add',
	knowledge_education_add: "knowledge_education_add",//获取问题id  //教学知识
	student_ergodic_query: 'student_ergodic_query',//老师查询学生信息
	query_student_goals: 'query_student_goals',//老师查询学生是否购买过课程
	teacher_teaching_record: 'teacher_teaching_record',//老师上课记录
	stduent_query_week_target: 'stduent_query_week_target',//学生设置课程目标
	student_target_update: 'student_target_update',//学生更新课程目标
	stduent_query_curriculum: 'stduent_query_curriculum',//老师查询学生购课记录（一对一）
	stduent_query_teacher_curriculum: 'stduent_query_teacher_curriculum',//学生查询所有上课记录
	select_mycourse_record: 'select_mycourse_record',//学生查询课程目标
	student_teacher_curriculum_query: 'student_teacher_curriculum_query',//学生查询课程记录
	anticipation_query: 'anticipation_query',//学生上课进度条查询
	refund: 'refund',//退款
	calendar_select: 'calendar_select',//根据日期查询老师课程记录
	video: 'video', //添加自我介绍视频
	update_video: 'update_video', //视频档案更新
	query_complete: 'query_complete',
	teacher_query_student: 'teacher_query_student',//搜索购买课程的学生
	teacher_query_j: 'teacher_query_j',//老师最近的上课时间
	student_generate_token: 'student_generate_token',//生成rtmtoken
	order_modification: 'order_modification',//课程记录
	query_teacher_puls: 'query_teacher_puls',//老师查询
	query_teacher_time_one: 'query_teacher_time_one',//时间段查询
	skill_query_name: 'skill_query_name',//查询老师当前课程名称
	video_call_token: 'video_call_token',//自动生成RTCtoken
	query_teacher_student_img: 'query_teacher_student_img',//查询当前上课详情
	student_teacher_query_skill: 'student_teacher_query_skill',//查询老师授课科目
}

//白名单api
let whiteApi = {
	query_teacher_puls: 'query_teacher_puls',
	teacher_not_examine: 'teacher_not_examine',
	student_generate_token: 'student_generate_token',
	teaching_period_query: 'teaching_period_query',
	query_teacher_time_one: 'query_teacher_time_one',
	login: 'login',
	student_phone_existence: 'student_phone_existence',
	verification_code: 'verification_code',
	student_mailbox_existence: 'student_mailbox_existence',
	sendEmail: 'sendEmail',
	student_mailbox_password: 'student_mailbox_password',
	student_phone_update: 'student_phone_update',
	mailbox_registration: 'mailbox_registration',
	learning_objectives_add: 'learning_objectives_add',
}

let header = {
	'Content-Type': 'application/json;charset=UTF-8',
	'gameProjectToken': localStorage.getItem('Token'),
}


//合并协议头
function extend(e, t) {

	for (var i in t) {

		e[i] = t[i];

	}

	return e;

}

//url 接口名称
//data 数据
//type 请求方式
//Protocol 是否返回原始数据内容，如res,req

async function ajax(url, data, type, head) {
	if (!whiteApi[url] && !localStorage.getItem('Token')) {

		window.location.href = '/index.html'
		Dreamer.error('请登录')
		// return false
	}
	head ? extend(head, header) : head = header //合并协议头
	return await $.ajax({
		url: host_http + api[url],
		type: type, //请求方式
		headers: head,
		timeout: 20000, //请求超时
		async: true, //异步或同步，默认异步
		dataType: 'json', //服务器返回类型 
		data: type.toLowerCase() == 'post' ? JSON.stringify(data) : data, //请求参数    
		success: function (res, txt, req) {
			// if (res.code == '401') {
			// 	window.location = 'Sign.html'
			// 	return
			// }
			if (url == 'login' || url == 'code_login' || url == 'phone_password_login' && res.code ==
				200 || url == 'mailbox_registration') {
				localStorage.setItem('Token', res.data.gameProjectToken);
				localStorage.setItem('user_Id', res.data.id);
				console.log(res);
			}
		},
		error: function (res) {

			Dreamer.warning('请先登录', 2000)

			return res
		}
	}).catch(e => { });

}


// 上传图片请求方法
async function getupload(file, res) {
	let name = Date.now();
	let formData = new FormData();
	formData.append('key', name)
	formData.append('OSSAccessKeyId', res.accessId)
	formData.append('policy', res.policy)
	formData.append('Signature', res.signature)
	formData.append('file', file);
	formData.append('success_action_status', 200);

	console.log('formData', formData)
	return new Promise(async (resolve, reject) => {
		return await $.ajax({
			url: http_img_download,
			data: formData,
			type: 'post', //请求方式
			timeout: 5000, //请求超时
			async: true, //异步或同步，默认异步
			// dataType: 'json', //服务器返回类型
			processData: false,
			contentType: false,
			success: function (r, txt, req) {
				let data = {
					code: 200,
					url: http_img_download + name
				};
				resolve(data)
			},
			error: function (r, txt, req) {
				reject(r, txt, req)
				// let data = {code:200,url:http_img_download + name};
				// return data
			}
		}).catch((e) => {
			reject(e, 'error')
		});
	})

}


async function upload(url, options) {
	let res = await ajax(url, { 'teacherimg': options }, 'post');
	if (res.code == 200) {
		return res
	}
}

// 老师档案查询内容
async function teacher() {
	let params = {
		token: localStorage.getItem('Token')
	}

	let res = await ajax('teacher_not_examine', params, 'post');

	if (res && res.code == 200) {

		let content = JSON.stringify(res);
		localStorage.setItem('archives', content);
	}

}
teacher();


// 上传图片
async function unploadimg(choose = 'element', size = (800 * 1024)) {
	let flie
	if (choose === 'element') {
		flie = $(choose).get(0).files[0];
	} else {
		flie = choose
	}

	if (!/^image\/(jpg|png|jpeg)$/.test(flie.type)) {

		Dreamer.warning("图片类型必须是jpg,png中的一种");
		return false;

	}
	// if (((flie.size).toFixed(2)) >= size) {

	// 	Dreamer.warning("请上传小于800k的图片");
	// 	return false;
	// }

	if (flie) {
		let res = await upload('getSign', flie)
		let getimg = await getupload(flie, res);
		return getimg
	}
}

//  processData: false,
//  contentType: false, 

//提示
function ts(data, time) {
	$(".ts-conten").text(data)
	$(".ts-index").css("display", "block");
	setTimeout(() => {
		$(".ts-index").css("display", "none");
	}, time)
}

// 跳转
function navgate(url) {
	window.location.href = url
}


// 支付数据初始化获取
async function payload(num = 1, paramspecial) {


	let { data } = await ajax('looking_teachers_money', paramspecial, 'post')
	// 缓存参数请求支付
	let pdata = {
		'teacherid': data.userid,
		'coursetime': data.coursetime,
		'timequantum': data.timequantum
	}

	localStorage.setItem('pdata', JSON.stringify(pdata));

	let week;

	switch (data.coursetime) {
		case 1:
			week = '一'
			break;
		case 2:
			week = '二'
			break;
		case 3:
			week = '三'
			break;
		case 4:
			week = '四'
			break;
		case 5:
			week = '五 '
			break;
		case 6:
			week = '六'
			break;
		case 7:
			week = '日'
			break;
	}


	if (num == 1) {
		let dates = `星期${week}`

		let times = `${data.timequantum}`
		$('.avtor').css("background-image", `url(${data.teacherimg})`);
		$('.teachname').html(data.teachername);
		$('#dates').html(dates);
		$('#times').html(times);
		$('#kind').html(data.dialect);
		$("#price").html('$' + data.price);

		let lastprice = '$' + data.price
		console.log(lastprice)
		$("#total").html(lastprice);

		let open = `确认付款 ${lastprice}`
		$('#open').html(open);

		let conform = `确认支付 ${lastprice}`

		$("#conform-btn").html(conform);

	} else {
		let { data } = await ajax('looking_teachers_money', paramspecial, 'post')
		let psval = `Your lesson with ${data.teachername} has been successfully scheduled`
		$("#pstitle").html(psval);

		let psdescripton = `We, 30 Jun,${data.timequantum}`;

		$("#psdescripton").html(psdescripton);
	}
}

// 获得年月日时分秒
function getDate() {
	let myDate = new Date();
	let times = `${myDate.getFullYear()}-${myDate.getMonth() + 1}-${myDate.getDate()} ${myDate.getHours()}:${myDate.getMinutes()}:${myDate.getSeconds()}`;


	return times;
}

// 手机号验证
function phonetest(ph) {
	var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
	if (myreg.test(ph)) {
		return true
	} else {
		return false
	}
}

// 邮箱验证
function emailtest(em) {
	var reg = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
	if (reg.test(em)) {
		return true
	} else {
		return false
	}
}
// 下拉
function downout() {
	var n = 0;
	$('.ic').click(function () {
		n++;
		objclassshow = {
			"margin-left: 9px;;font-size": "30px",
			"color": "#BDBDBD",
			"transform": "rotate(450deg) scale(0.6)",
			"transition": "transform 0.5s ease-in"
		}
		objclasshide = {
			"margin-left: 9px;;font-size": "30px",
			"color": "#BDBDBD",
			"transform": "rotate(270deg) scale(0.6)",
			"transition": "transform 0.5s ease-in"
		}
		if (n % 2 == 0) {
			$('.ic').css(objclasshide);
		} else {
			$('.ic').css(objclassshow);
		}
		$('.select-lang').toggle();
	})
}


// 返回上一层
function goback() {
	window.history.back(-1);
}

// 完成进度显示
function productlist(num) {
	for (let j = 0; j < 5; j++) {
		$('.box-first').eq(j).css({
			'background-color': '',
			'color': ''
		});
	}
	if (num < 7) {
		for (let i = 0; i < num; i++) {
			if (i < num - 1) {
				$('.box-first').eq(i).css({
					'background-color': '#5686E9',
					'color': '#fff'
				});
			} else {
				$('.box-first').eq(i).css('background-color', '#fff');
			}
		}
	}
}

// 动态加载css
function loadStyle(url) {
	var link = document.createElement('link');
	link.type = 'text/css';
	link.rel = 'stylesheet';
	link.href = url;
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(link);
}

// 动态生成js
function loadScript(url) {

	var element = document.createElement('script');

	element.setAttribute('src', url);
	return document.body.appendChild(element);
}


// 保存按钮生成
function savebtn() {
	let savebtn = `<button type="button" class="save-btn">保存</button>`

	$('.btn-save').empty();
	$('.btn-save').append(savebtn);

}


// 生成header-list
let productitem = `<div class="select-item">
					<div class="box-first"></div>
					<span></span>
					<i class="iconfont icon-xiangyou1"></i>
				</div>`
let listarray = ['信息', '照片', '描述', '短视频', '授课时间'];
for (let i = 0; i < listarray.length; i++) {
	$('.select-content').append(productitem);
	$('.box-first').eq(i).html(i + 1);
	$('.select-item').find('span').eq(i).html(listarray[i]);
}

// teacher页容器
let teachercontainer = document.getElementsByClassName('teach-container');


// 注册之后直接登录
async function publicLogin() {

	// 取得账号
	let rlogin;

	if (localStorage.getItem('params')) {

		rlogin = JSON.parse(localStorage.getItem('params'))

	}


	if (phonetest(rlogin.mailbox) && rlogin.password) {
		//手机登录
		let params = {
			'phone': rlogin.mailbox,
			'password': rlogin.password,
		};

		let res = await ajax('phone_password_login', params, 'POST');
		if (res.code == 200) {
			// 记住密码
			if ($(".check-box").prop('checked')) {
				// 转换格式存储
				let temp = {
					'mailbox': rlogin.mailbox,
					'password': rlogin.password,
				}

				localStorage.setItem('params', JSON.stringify(temp));

			} else {
				localStorage.removeItem('params');
			}
			Dreamer.success("登录成功", 2000);
			window.location.href = '/views/teacher/teachers.html';
		} else {
			Dreamer.error("登录失败！", 2000);
		}
	} else if (emailtest(rlogin.mailbox) && rlogin.password) {

		//邮箱登录
		let params = {
			'mailbox': rlogin.mailbox,
			'password': rlogin.password,
		}
		let res = await ajax('login', params, 'POST');
		if (res && res.msg != '未找到该用户') {


			// 记住密码
			localStorage.setItem('information', JSON.stringify(res.data));
			Dreamer.success("登录成功", 2000);

			let r = JSON.parse(localStorage.getItem('information'))

			let obj = {

				user_id: (r.id).toString(),
				user_name: r.teachername,
				user_img: r.teacherimg,
			}

			localStorage.setItem('user', JSON.stringify(obj))
			window.location.href = '/views/teacher/teachers.html';
		} else {

			Dreamer.error("登录失败！", 2000);
		}
	} else {

		Dreamer.error("登录失败,请检查账号密码是否输入正确！", 2000);
	}
}



// 页头生成
function productheader(obj, num, selectindex = 1, headerChange = 0) {
	let one = `
	<div class="header-top">
		<div class="content">
			<img src="/static/icon.png"  class="icon loginindex">
			<div class="title-bar">
				<a href=" /views/teacher/teachers.html"><span data-i18n-text="AnnualAvg">寻找老师</span></a>
				<a href="/views/register/teacherregist.html"><span>成为老师</span></a>
				<a href="/views/company/company.html"><span>企业培训</span></a>
			</div>
		</div>
		<div class="content" id="left-go">
				<i class="iconfont icon-xinxi" style="font-size: 30px;color: #BDBDBD;display:none"></i>
				<div class="title-right-bar">
					<span>中文,</span>
					<span id="sp2">USD</span>
					<i class="iconfont icon-xiang-zuo ic apps"></i>
				<div class="select-lang">
					<div>
						<h3>语言</h3>
							    <select name="">
								  <option value=" ">中文</option>
								  <option value="实验1">英文</option>
								  <option value="实验2">德语</option>
								</select>
					</div>
					<div>
						<h3>货币</h3>
						<select>
						  <option value ="volvo">USD</option>
						  <option value ="saab">USD</option>
						</select>
					</div>
				</div>
				</div>
				<div class='left-bar'>
					<a href="/views/question/question.html" id="qweww"><i class="iconfont icon-wenhao i-question"></i></a>
					<i class="iconfont icon-morentouxiang" style="font-size: 25px;color: #BDBDBD;margin-left: 16px;"></i>
					<span class="loginin">登录</span>
				</div>
		</div>
	</div>`

	let two = `
	<div class="header-top">
		<div class="content">
			<img src="/static/icon.png"  class="icon loginindex">
			<div class="title-bar">
				<a href="/views/teacher/teachers.html"><span data-i18n-text="AnnualAvg">寻找老师</span></a>
			</div>
		</div>
		<div class="content">
				<ul>
					<li>时区:<span id="tiemarea"></span></li>
					<li>当前时间:<span class="timeNow"></span></li>
					<li>
						<svg t="1637235382978" class="icon" style="width: 14px;height: 14px;" viewBox="0 0 1190 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6062" width="200" height="200"><path d="M485.748736 23.259264l474.491373 449.906328a85.465381 85.465381 0 0 1 3.234874 120.466722L670.136575 903.015698a85.465381 85.465381 0 0 1-120.466722 3.234875L75.17848 456.279548a85.465381 85.465381 0 0 1-3.234874-120.466722L365.282014 26.494139a85.465381 85.465381 0 0 1 120.466722-3.234875z m0 0" fill="#FEC50D" p-id="6063"></path><path d="M319.088008 69.19448L929.702894 303.0112a85.546253 85.546253 0 0 1 49.170091 109.985729L826.510402 811.274661a85.546253 85.546253 0 0 1-109.985729 49.170091L105.715694 626.498637a85.546253 85.546253 0 0 1-49.17009-109.985728L208.972884 118.364571a85.578602 85.578602 0 0 1 110.115124-49.170091z m0 0" fill="#44C0D9" p-id="6064"></path><path d="M115.937897 212.305323h889.331663a116.245211 116.245211 0 0 1 115.937897 115.937897v579.818883a116.245211 116.245211 0 0 1-115.937897 115.937897H115.937897A116.245211 116.245211 0 0 1 0 908.062103V328.24322a116.245211 116.245211 0 0 1 115.937897-115.937897z m0 0" fill="#005B7D" p-id="6065"></path><path d="M958.299184 951.215327H890.237427v-17.01544h68.061757z m-136.123514 0h-68.061756v-17.01544h68.061756z m-135.994118 0h-68.061757v-17.01544h68.061757z m-135.994119 0h-68.061757v-17.01544h68.061757z m-136.123513 0h-68.061757v-17.01544H414.06392z m-135.994119 0h-68.061757v-17.01544h68.061757z m-136.123514 0H115.808503A43.040004 43.040004 0 0 1 72.784673 908.062103v-13.845263h16.950742v13.845263A26.00839 26.00839 0 0 0 115.808503 934.070492h26.137784z m887.973016-7.893094l-9.834019-13.974657a26.024564 26.024564 0 0 0 11.127968-21.350171v-34.936643H1048.099296v34.936643a42.570947 42.570947 0 0 1-18.244691 35.324828zM89.929508 826.284478H72.978766v-68.061756H89.929508z m958.299183-21.026683H1031.27795v-68.126454h16.950741zM89.929508 690.160965H72.978766v-68.061757H89.929508z m958.299183-21.026684H1031.27795v-68.126454h16.950741z m-958.299183-114.83804H72.978766v-68.191152H89.929508z m958.299183-21.026683H1031.27795v-68.255849h16.950741zM89.929508 418.043333H72.978766v-68.061757H89.929508z m958.299183-21.026684H1031.27795v-67.997059h16.950741z m-938.372357-94.134844l-3.88185-16.562557a42.538598 42.538598 0 0 1 9.834019-1.164555h60.039268v16.950742H115.808503a46.905678 46.905678 0 0 0-5.952169 0.77637z m882.344333-0.646975h-68.061756v-16.950742h68.061756z m-136.123513 0H788.015397v-16.950742h68.061757z m-135.994119 0h-68.061757v-16.950742h68.061757z m-135.994118 0H515.962462v-16.950742h68.061757z m-136.123514 0h-68.061757v-16.950742H448.030101z m-135.994119 0H243.909528v-16.950742h68.061756z m0 0" fill="#44C0D9" p-id="6066"></path><path d="M909.129093 483.51719h210.91381A70.633482 70.633482 0 0 1 1190.433769 553.908056v128.359815a70.633482 70.633482 0 0 1-70.390866 70.390867h-210.91381a134.570774 134.570774 0 0 1 0-269.141548z m0 0" fill="#FEC50D" p-id="6067"></path><path d="M1006.434115 618.023266a48.005536 48.005536 0 1 0 48.005535-48.005535 48.005536 48.005536 0 0 0-48.005535 48.005535z m0 0" fill="#FFFFFF" p-id="6068"></path></svg>
						<span style="margin-left: 7px;">金额:</span>
						<span style="margin-left: 7px;">123节课</span>
						<button type="button" class="btn-green" style="margin-left: 7px;">购买</button>
						<button type="button" class="btn-green-border" style="margin-left: 7px;">邀请朋友</button>
					</li>
				</ul>	
				<div class="title-right-bar">
					<span>中文,</span>
					<span  id="sp2" >USD</span>
					<i class="iconfont icon-xiang-zuo ic apps"></i>
				<div class="select-lang">
					<div>
						<h3>语言</h3>
							    <select name="">
								  <option value="">中文</option>
								  <option value="实验1">英文</option>
								  <option value="实验2">德语</option>
								</select>
					</div>
					<div>
						<h3>货币</h3>
						<select>
						  <option value ="volvo">USD</option>
						  <option value ="saab">USD</option>
						</select>
					</div>
				</div>
				</div>
				<div class='left-bar'>
					<i class="iconfont icon-xinxi "></i>
					<a href="/views/question/teacher.html"><i class="iconfont icon-xinxi icon-wenhao "></i></a>
				<!--	<i class="iconfont icon-aixin"></i>
					<i class="iconfont icon-xiangling"></i> -->
					<i class="iconfont icon-morentouxiang" id ="threeicon" style="font-size: 25px;color: #BDBDBD;"></i>
					<span class="loginin">登录</span>
				</div>
		</div>
	</div>`




	// h获取gmt的偏移分钟
	function offsets() {
		var nowTime = new Date()
		var offset1 = nowTime.getTimezoneOffset() / 60
		return -offset1
	}

	let template;

	if (selectindex == 1) {
		template = one;
	} else {
		template = two;


		tingtime = setInterval(() => {

			let d = new Date();

			let hours = `${d.getHours() < 10 ? '0' + d.getHours() : d.getHours()
				} : ${d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()}: ${d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds()}`;

			// document.getElementsByClassName('timeNow')[0].innerHTML = hours;

		}, 1000)
	}

	switch (num) {
		case 1:
			$(obj).before(template);
			break;
		case 2:
			$(obj).after(template);
			break;
		case 3:
			$(obj).prepend(template);
			break;
		case 4:
			$(obj).append(template);
			break;
	}


	downout();
	gostuTeacher();

	// 页头切换
	if (headerChange == 1) {

		$(".loginin").hide();
		$(".content ul").empty();
		let tempatrue = `<li class="s-flex">
						<svg t="1637235382978" class="icon" style="width: 14px;height: 14px;" viewBox="0 0 1190 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6062" width="200" height="200"><path d="M485.748736 23.259264l474.491373 449.906328a85.465381 85.465381 0 0 1 3.234874 120.466722L670.136575 903.015698a85.465381 85.465381 0 0 1-120.466722 3.234875L75.17848 456.279548a85.465381 85.465381 0 0 1-3.234874-120.466722L365.282014 26.494139a85.465381 85.465381 0 0 1 120.466722-3.234875z m0 0" fill="#FEC50D" p-id="6063"></path><path d="M319.088008 69.19448L929.702894 303.0112a85.546253 85.546253 0 0 1 49.170091 109.985729L826.510402 811.274661a85.546253 85.546253 0 0 1-109.985729 49.170091L105.715694 626.498637a85.546253 85.546253 0 0 1-49.17009-109.985728L208.972884 118.364571a85.578602 85.578602 0 0 1 110.115124-49.170091z m0 0" fill="#44C0D9" p-id="6064"></path><path d="M115.937897 212.305323h889.331663a116.245211 116.245211 0 0 1 115.937897 115.937897v579.818883a116.245211 116.245211 0 0 1-115.937897 115.937897H115.937897A116.245211 116.245211 0 0 1 0 908.062103V328.24322a116.245211 116.245211 0 0 1 115.937897-115.937897z m0 0" fill="#005B7D" p-id="6065"></path><path d="M958.299184 951.215327H890.237427v-17.01544h68.061757z m-136.123514 0h-68.061756v-17.01544h68.061756z m-135.994118 0h-68.061757v-17.01544h68.061757z m-135.994119 0h-68.061757v-17.01544h68.061757z m-136.123513 0h-68.061757v-17.01544H414.06392z m-135.994119 0h-68.061757v-17.01544h68.061757z m-136.123514 0H115.808503A43.040004 43.040004 0 0 1 72.784673 908.062103v-13.845263h16.950742v13.845263A26.00839 26.00839 0 0 0 115.808503 934.070492h26.137784z m887.973016-7.893094l-9.834019-13.974657a26.024564 26.024564 0 0 0 11.127968-21.350171v-34.936643H1048.099296v34.936643a42.570947 42.570947 0 0 1-18.244691 35.324828zM89.929508 826.284478H72.978766v-68.061756H89.929508z m958.299183-21.026683H1031.27795v-68.126454h16.950741zM89.929508 690.160965H72.978766v-68.061757H89.929508z m958.299183-21.026684H1031.27795v-68.126454h16.950741z m-958.299183-114.83804H72.978766v-68.191152H89.929508z m958.299183-21.026683H1031.27795v-68.255849h16.950741zM89.929508 418.043333H72.978766v-68.061757H89.929508z m958.299183-21.026684H1031.27795v-67.997059h16.950741z m-938.372357-94.134844l-3.88185-16.562557a42.538598 42.538598 0 0 1 9.834019-1.164555h60.039268v16.950742H115.808503a46.905678 46.905678 0 0 0-5.952169 0.77637z m882.344333-0.646975h-68.061756v-16.950742h68.061756z m-136.123513 0H788.015397v-16.950742h68.061757z m-135.994119 0h-68.061757v-16.950742h68.061757z m-135.994118 0H515.962462v-16.950742h68.061757z m-136.123514 0h-68.061757v-16.950742H448.030101z m-135.994119 0H243.909528v-16.950742h68.061756z m0 0" fill="#44C0D9" p-id="6066"></path><path d="M909.129093 483.51719h210.91381A70.633482 70.633482 0 0 1 1190.433769 553.908056v128.359815a70.633482 70.633482 0 0 1-70.390866 70.390867h-210.91381a134.570774 134.570774 0 0 1 0-269.141548z m0 0" fill="#FEC50D" p-id="6067"></path><path d="M1006.434115 618.023266a48.005536 48.005536 0 1 0 48.005535-48.005535 48.005536 48.005536 0 0 0-48.005535 48.005535z m0 0" fill="#FFFFFF" p-id="6068"></path></svg>
						<span style="margin-left: 7px;">9999.00</span>
						<select  class="s-money">
						  <option value ="volvo">USD</option>
						  <option value ="saab">USD</option>
						</select>
					</li>`


		$(".content ul").append(tempatrue);
		$(".content ul").css("position", "relative");
		$(".content ul").css("left", "36px");
		$(".title-right-bar").css("border", "none");
		$(".ic").css("position", "relative");
		$(".ic").css("right", "34px");


		// 设置坐标标题
		$(".title-bar").css("height", "100%");
		$(".title-bar").css("border-left", "1px solid #ddd6d6");
	}

	let timearea = Intl.DateTimeFormat().resolvedOptions().timeZone;



	$('#tiemarea').html(timearea)

	$(".loginin").click(function () {


		if ($('.loginin').html() == '退出') {

			$('.loginin').html('登录');

			let message = JSON.parse(localStorage.getItem('params')) || JSON.parse(localStorage.getItem('params'))

			let params = {

				'mailbox': message.mailbox,
				'password': message.password,
			}

			localStorage.clear();

			localStorage.setItem('params', JSON.stringify(params))

			window.location.href = "/index.html";
		} else {

			window.location.href = '/index.html';

		}
	})



	$('.icon-morentouxiang').click(function () {

		let information = JSON.parse(localStorage.getItem('information'));


		if (information && information.state == 1) {

			window.location.href = '/views/menu/teacher/arrearage.html'

		} else if (information && information.state == 0) {

			window.location.href = '/views/menu/student/arrearage.html'

		} else {

			window.location.href = '/index.html'

		}

	})

	$('.icon-xinxi').click(function () {

		let information = JSON.parse(localStorage.getItem('information'));


		if (information && information.state == 1) {

			window.location.href = '/views/menu/teacher/arrearage.html'

		} else if (information && information.state == 0) {

			window.location.href = '/views/menu/student/arrearage.html'

		} else {

			window.location.href = '/index.html'

		}

	})


	$('.loginindex').click(function () {

		window.location.href = '/views/teacher/teachers.html'

	})


	$('.btn-green-border').click(function (params) {

		window.location.href = '/views/invite/invitation.html'
	})
}

$('.loginindex').click(function () {

	window.location.href = '/views/teacher/teachers.html'

})
//默认调用一次，初始化处理 
gostuTeacher();
function gostuTeacher() {

	let Token = localStorage.getItem('Token')

	if (Token) {

		let information = JSON.parse(localStorage.getItem('information'));

		if (information && information.teacherimg) {

			// $('.loginin').hide();
			$('#threeicon').hide();
			$('.icon-morentouxiang').hide();
			let image = new Image();

			image.width = 22;
			image.height = 22;
			image.className = 'avatar';
			image.src = information.teacherimg;

			image.style.border = '1px solid #fff';
			image.style.margin = '0 8px';
			image.style.cursor = 'pointer';
			image.style.borderRadius = 50 + '%';

			image.onclick = function () {

				if (information.state == 1) {

					window.location.href = '/views/menu/teacher/arrearage.html'

				} else if (information.state == 0) {

					window.location.href = '/views/menu/student/arrearage.html'

				} else {

					window.location.href = '/views/teacher/teachers.html'

				}

			}

			$('.loginin').before(image)

		}
		$('.loginin').html('退出');

	} else {


	}
}

// 页尾生成
function productfooter(obj, num) {
	let template = `
		<div class="footer-container">
		<div class="footer-btm">
			<div class="two-title">
				<div class="footer-flex-two">
					<a href="/views/teacher/teachers.html" id="sp-special-white">热门科目</a>
					<a href="/views/teacher/teachers.html">汉语日常口语</a>
					<a href="/views/teacher/teachers.html" id="sp-special">商务汉语</a>
					<a href="/views/teacher/teachers.html" id="sp-special">儿童汉语</a>
					<a href="/views/teacher/teachers.html" id="sp-special">台湾华语</a>
					<a href="/views/teacher/teachers.html" id="sp-special">粤语（広東話）</a>
				</div>
				<div class="footer-flex-two">
					<a href="/views/teacher/teachers.html" id="sp-special-white">热门城市</a>
					<div class="tz">
						<a href="/views/teacher/teachers.html">上海</a>
						<a href="/views/teacher/teachers.html">台北</a>
						<a href="/views/teacher/teachers.html">洛杉矶</a>
					</div>
					<div class="tz">
						<a href="/views/teacher/teachers.html">广州</a>
						<a href="/views/teacher/teachers.html">新加坡</a>
						<a href="/views/teacher/teachers.html">旧金山</a>
					</div>
					<div class="tz">
						<a href="/views/teacher/teachers.html">青岛</a>
						<a href="/views/teacher/teachers.html">东京</a>
						<a href="/views/teacher/teachers.html">温哥华</a>

					</div>
					<div class="tz">
						<a href="/views/teacher/teachers.html">大连</a>
						<a href="/views/teacher/teachers.html">首尔</a>
						<a href="/views/teacher/teachers.html">多伦多</a>
					</div>
					<div class="tz">
						<a href="/views/teacher/teachers.html">北京</a>
						<a href="/views/teacher/teachers.html">悉尼</a>
						<a href="/views/teacher/teachers.html">伦敦</a>
					</div>
					<div class="tz">
						<a href="/views/teacher/teachers.html">深圳</a>
						<a href="/views/teacher/teachers.html">墨尔本</a>
						<a href="/views/teacher/teachers.html">巴黎</a>
					</div>
					<div class="tz">
						<a href="/views/teacher/teachers.html">香港</a>
						<a href="/views/teacher/teachers.html">纽约</a>
					</div>
				</div>
				<div class="footer-flex-three">
					<a id="sp-special-white">热门汉语考试</a>
					<a href="/views/teacher/teachers.html">HSK</a>
					<a href="/views/teacher/teachers.html">BCT</a>
					<a href="/views/teacher/teachers.html">YCT</a>
				</div>
			</div>
			<div class="secondbox common">
				<div class="boxstyle">
					<a href="/views/lllustration/lllustration.html">about us</a>
					<a href="/views/question/teacher.html">help</a>
				</div>
				<div class="boxstyle">
					<a href="views/register/teacherregist.html">成为老师</a>
				</div>
				<div class="boxstyle">
					<a href="views/invite/invitation.html">邀请朋友</a>
					<a href="views/register/teacherregist.html">招聘老师</a>
				</div>
				<div class="boxstyle">
					<a href="views/company/company.html">企业培训</a>
				</div>
			</div>
			<div class="threebox common">
				<div class="boxstyle">
					<a href="views/company/company.html">联系方式</a>
					<a href="">
						<i class="iconfont icon-youjian i-email"></i>
						<span class="fs">info@chineselessons.onine</span>
					</a>
				</div>
				<div>
					<div class="boxstyle">
						<a href="" style="color: #888888;">USA <span class="fs">651 N Broad St, Suite 206,
								Middletown,
								DE 19709</span></a>
					</div>
					<div class="boxstyle">
						<a href="" style="color: #888888;">中国 <span class="fs">上海市嘉定区万镇路599号</span></a>
					</div>
				</div>
			</div>
			<div class="threebox common">
				<div class="boxstyle">
					<a href="">用户条款</a>
				</div>
				<div class="boxstyle">
					<a href="">支付退款政策</a>
				</div>
				<div class="boxstyle">
					<a href="">隐私条款</a>
				</div>
				<div class="boxstyle">
					<a href="">cookie条款</a>
				</div>
			</div>
			<div class="threebox common" style="padding-bottom: 25px;">
				<div class="boxstyle">
					<a href=""><img src="/static/footerimage/download.png" alt="download.png"></a>
				</div>
				<div class="boxstyle">

					<a href=""><img src="/static/footerimage/bct.png" alt="bct.png"></a>

				</div>
				<div class="boxstyle">

					<a href=""><img src="/static/footerimage/yct.png" alt="yct.png"></a>

				</div>
				<div class="boxstyle">

					<a href=""><img src="/static/footerimage/jcea.png" alt="jcea.png"></a>

				</div>
			</div>
		</div>
	</div>`
	switch (num) {
		case 1:
			$(obj).before(template);
			break;
		case 2:
			$(obj).after(template);
			break;
		case 3:
			$(obj).prepend(template);
			break;
		case 4:
			$(obj).append(template);
			break;
	}
	// 跳转方法
	$('.footer-content').click(() => locationhtml);

	$('.two-title').click(() => locationhtml);

	function locationhtml() {
		window.location.href = '/views/teacher/teachers.html';
	}
}

//动态生成rtctoken
(async function getRtcToken() {
	let res = await ajax('student_generate_token', {}, 'post')
	if (res) {
		localStorage.setItem('rtmToken', res.msg)
	}
})()



// 学生需求查询
let loadData;
async function initData(location, choose = 1) {

	let params = {
		PageSize: 10,
		pageNum: 3
	}

	let res = await ajax('student_task_query1', params, 'post');

	if (res.code == 200) {

		$('.top-ul-list').remove();

		loadData = res.data.list[0];

		let money = `每小时${loadData.startmoney}$`;

		let content = loadData.promulgationcontent;

		let dtime = loadData.createtime;

		$('.money').html(money);
		$('.taskcon').html(content);
		$('.datetimenow').html(dtime);


		console.log(res.data.list)

		for (let i = 1; i < res.data.list.length; i++) {
			if (i < 5) {
				let tasks = `
		< div class= "top-ul-list" >
							<div class='top-ul-list-top1'>
								<span style='color:#717171;font-size: 14px;'>儿童汉语</span>
								<div class="top-ul-list-top1-money">${res.data.list[i].startmoney}$</div>
							</div>
							<div class="top-ul-list-top2">
								<div></div>
								<div class="top-ul-list-top1-money">每小时</div>
							</div>
							<div class="top-ul-list-top3">${res.data.list[i].promulgationcontent}</div>
							<div class="top-ul-list-top4">
								<div id="require-next"></div>
								<div class="top-ul-btn">立即注册以申请</div>
							</div>
						</div > `;
				$(location).append(tasks);

				if (choose == 1) {
					$('.top-ul-btn').click(function () {
						window.location.href = '/views/register/teacherregist.html';
					})
				} else {
					$('.top-ul-btn').html('立即回答');
				}
			} else {
				return
			}
		}
	} else {
		Dreamer.warning('查询失败', 2000)
	}
}

let timeout = null

/**
 * 防抖原理：一定时间内，只有最后一次操作，再过wait毫秒后才执行函数
 *
 * @param {Function} func 要执行的回调函数
 * @param {Number} wait 延时的时间
 * @param {Boolean} immediate 是否立即执行
 * @return null
 */
function debounce(func, wait = 500, ...arg) {
	let immediate = false;
	// 清除定时器
	if (timeout !== null) clearTimeout(timeout)
	// 立即执行，此类情况一般用不到
	if (immediate) {
		const callNow = !timeout
		timeout = setTimeout(() => {
			timeout = null
		}, wait)
		if (callNow) typeof func === 'function' && func(...arg)
	} else {
		// 设置定时器，当最后一次操作后，timeout不会再被清除，所以在延时wait毫秒后执行func回调方法
		timeout = setTimeout(() => {
			typeof func === 'function' && func(...arg)
		}, wait)
	}
}


let timer; let
	flag
/**
 * 节流原理：在一定时间内，只能触发一次
 *
 * @param {Function} func 要执行的回调函数
 * @param {Number} wait 延时的时间
 * @param {Boolean} immediate 是否立即执行
 * @return null
 */
function throttle(func, wait = 500, immediate = true) {
	if (immediate) {
		if (!flag) {
			flag = true
			// 如果是立即执行，则在wait毫秒内开始时执行
			typeof func === 'function' && func()
			timer = setTimeout(() => {
				flag = false
			}, wait)
		}
	} else if (!flag) {
		flag = true
		// 如果是非立即执行，则在wait毫秒内的结束处执行
		timer = setTimeout(() => {
			flag = false
			typeof func === 'function' && func()
		}, wait)
	}
}

let ctimer = null;

function debouncecustom(func, delay) {

	if (ctimer) {
		clearTimeout(ctimer)
	}

	ctimer = setTimeout(() => {

		func()

	}, delay)
}


let voild = true;

function throttlecustom(func, delay) {

	if (!voild) {

		return false
	}

	voild = false
	setTimeout(() => {
		func()
		voild = true;
	}, delay)

}




